package com.hxz.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hxz.entity.Article;
import com.hxz.service.ArticleService;

import io.swagger.annotations.Api;

@Controller
@Api(description = "博客主页面controller")
@RequestMapping("/index")
public class IndexController {
	@Autowired
	private ArticleService articleService;
	/**
	 * 博客首页面
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/show")
	public String index() throws Exception {
		return "front/article";
	}
	/**
	 * 获取文章前三
	 * @return
	 */
	@RequestMapping("/top3")
	@ResponseBody
	public List<Article> getTop3(){
		List<Article> top3=articleService.getTop3();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String s = sdf.format(new Date());
		for (int i = 0; i < top3.size(); i++) {
			top3.get(i).setDate(s);
		}
		return top3;
	}
}
